/**
*  Copyright 2009-2014 by WWW.KNET.CN  All rights reserved.
*/
package com.domain.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.domain.model.Sysuser;
import com.domain.util.commonUtil;


/**
 * TODO(这里用一句话描述这个类的作用)
 * @author liujie
 * @date 2015年4月16日 下午2:14:58
 * 
 */
public class SuperController {
	private static final Logger logger = LoggerFactory.getLogger(SuperController.class);
	public static final String CURRENT_LOGIN_USER = "currentLoginUser";
	public static final String PAGE_NAME = "page";
	public static final String POR_CODE = "porCode";
	public static final String PAGESIZE_NAME = "pagesize";
	public static final int PAGE = 1;
	public static final int PAGESIZE = 20;
	

	/**
	 * 获取代理之后的 ip
	 * 
	 * @param request
	 * @return
	 */
	public String getRemoteIP(HttpServletRequest request) {
		String ip = request.getHeader("x-forwared_for");
		if (StringUtils.isNotBlank(ip)) {
			return ip;
		}
		ip = request.getRemoteAddr();
		return ip;
	}
	public Sysuser getCurrentUser(HttpServletRequest request){
		HttpSession session = request.getSession();
		try {
			Sysuser account =(Sysuser) session.getAttribute(commonUtil.CURRENTUSER);
			session.setAttribute(commonUtil.CURRENTUSER, account);
			if (null==account) {
				return null;
			}else 
				return account;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("------------------登录对象超时:"+e.getMessage());
			return null;
		}
	}
	
}
